const Koa = require("koa");
const app = new Koa();

const router = require("./router");
const bodyParser = require("koa-bodyparser");
const koaStatic = require("koa-static");

const parameter = require("koa-parameter");
const jsonerror = require("koa-json-error");

app.use(parameter(app));
app.use(koaStatic(__dirname + "/static"));
app.use(bodyParser());
app.use(router.routes());

function formatError(err) {
  return {
    status: err.status,
    message: err.message,
    success: false,
    reason: "Unexpected",
  };
}

app.use(jsonerror(formatError));

app.listen(3000, () => {
  console.log("3000 running");
});
